package vip.specimen.system.datasource.validation.implement;


import vip.specimen.system.datasource.entity.SystemUserEntity;
import vip.specimen.system.datasource.validation.annotation.PhoneUnique;
import vip.specimen.system.service.SystemUserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * *@Author: 余浪人
 * *@Date：2021/3/23 17:16
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class PhoneUniqueImp implements ConstraintValidator<PhoneUnique, String> {
    @Resource
    private SystemUserService userService;
    @Resource
    private HttpServletRequest request;

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (null == s) return true;
        SystemUserEntity userEntity = this.userService.findByPhone(s);
        return (null == userEntity || userEntity.getUuid().toString().equals(request.getParameter("uuid")));
    }
}
